import { createRoute, createRouterMap } from "./createRouterMap";

export function createMatch(routers) {//匹配器
    //变成一个路由映射表  [{}{}]=>{'/',{组件相关信息}}
    const pathMap  = createRouterMap(routers)

    //后添加的路由进行合并
    function addRoutes(routes) {
        createRouterMap(routes, pathMap)
    }
    function match(location) {
        let recode = pathMap[location]
        if (recode) {
            return createRoute(recode, { path: location })
        }
        return createRoute(null, { path: location })
    }
    return {
        addRoutes,
        match
    }
}